<template>
    <div class="user-add">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
            <el-form-item prop="userName" label="用户名" style="width:50%" >
                <el-input v-model="form.userName" placeholder="用户名" clearable ></el-input>
            </el-form-item>
            <el-form-item prop="phone" label="手机号" style="width:50%" >
                <el-input v-model="form.phone" placeholder="手机号" clearable ></el-input>
            </el-form-item>
            <el-form-item>
                <el-button @click="back" icon="el-icon-back">返回</el-button>
                <el-button type="primary" @click="userAdd" icon="el-icon-success">提交</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    data() {
        return {
           form:{
                phone:'',
                userName:''
            },
            rules:{
                phone:[{required:true,message:"请输入手机号"}],
                userName:[{required:true,message:"请输入用户名"}]
            } 
        }
    },
    created() {
        let tab=[{name:'用户列表',path:'user'}, {name:'新增用户',path:'userAdd'}];
        //this.$store.commit('_setTab',tab);
    },
    methods:{
        userAdd() {
            this.$api.regByAdmin(this.form).then((res)=>{
                this.$com.toast("添加成功！")
            })
        },
        back() {
            this.$router.go(-1);
        }
    }
}
</script>

<style lang="scss" scoped>
    .user-add{
        margin-top: 40px;

    }
</style>
